home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 551-575 / disk_562 / intuisup / editor / source.lzh / main.c < prev    next >
C/C++ Source or Header  |  1991-10-19  |  5KB  |  169 lines

  1.         /*************************************
  2.          *                                   *
  3.          *             Editor v1.0           *
  4.          *   by Torsten Jürgeleit in 07/91   *
  5.          *                                   *
  6.          *              Main part            *
  7.          *                                   *
  8.          *************************************/
  9.  
  10.     /* Includes */
  11.  
  12. #include "includes.h"
  13. #include "defines.h"
  14. #include "imports.h"
  15. #include "protos.h"
  16.  
  17.     /* Globals */
  18.  
  19. struct IntuitionBase    *IntuitionBase;
  20. struct GfxBase        *GfxBase;
  21. struct ArpBase        *ArpBase;
  22. struct Library        *IntuiSupBase = NULL;   /* Clear for show_error() */
  23. struct Library        *DiskfontBase;
  24.  
  25. struct Screen        wb_screen;
  26. struct Window        *ewin, *pwin;
  27. struct TextAttr        topaz60_attr = { (STRPTR)"topaz.font", TOPAZ_SIXTY,
  28.                            FS_NORMAL, FPF_ROMFONT },
  29.             topaz80_attr = { (STRPTR)"topaz.font", TOPAZ_EIGHTY,
  30.                            FS_NORMAL, FPF_ROMFONT };
  31. struct NewWindow    project_new_window = {
  32.    0, 0, 0, 0, PROJECT_WINDOW_DETAIL_PEN, PROJECT_WINDOW_BLOCK_PEN,
  33.    PROJECT_WINDOW_IDCMP, PROJECT_WINDOW_FLAGS, NULL, NULL,
  34.    PROJECT_WINDOW_TITLE, NULL, NULL, PROJECT_WINDOW_MIN_WIDTH,
  35.    PROJECT_WINDOW_MIN_HEIGHT, -1, -1, WBENCHSCREEN
  36. };
  37.  
  38. struct TemplateList    template_list;
  39. struct Template        *selected_template,
  40.             *info_template;
  41. struct Box        current_box;
  42.  
  43. struct GadgetData    *use_gd;
  44. struct FileRequester    *project_file_requester,
  45.             *csource_file_requester;
  46.  
  47. struct Dimension    min_dimension[MAX_TEMPLATE_TYPES] = {
  48.     { 20, 10 }, { 0, 0 }, { 20, 10 }, { 21, 11 }, { 50, 10 }, { 30, 8 },
  49.     { 30, 8 }, { 20, 8 }, { 20, 8 }, { 50, 10 }, { 40, 10 },
  50.     { 40, 30 }, { 60, 30 } };
  51.  
  52. APTR    eri, pri, egl, eml, use_gl;
  53.  
  54. BYTE    *default_mx_text_array[] = { "MX1", "MX2", NULL },
  55.     *default_cycle_text_array[] = { "Cycle", "Test 1", "Test 2", NULL },
  56.     *default_listview_text_array[] = { "Entry 1", "Entry 2", "Entry 3",
  57.              "Entry 4", "Entry 5", "Entry 6", "Entry 7", "Entry 8",
  58.                        "Entry 9", "Entry 10", NULL };
  59. BYTE    project_window_title[80];
  60.  
  61. USHORT    snap_offset_table[] = { 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 };
  62.  
  63. USHORT    editor_mode = DEFAULT_EDITOR_MODE,
  64.     snap_offset = DEFAULT_SNAP_OFFSET,
  65.     template_type = DEFAULT_TEMPLATE_TYPE;
  66.  
  67. USHORT    modify_mode = 0, mouse_button = 0;
  68. SHORT    last_snap_x, last_snap_y;
  69.  
  70. BOOL    info_displayed = FALSE;
  71.  
  72.     /* Statics */
  73.  
  74. STATIC struct NewWindow  editor_new_window = {
  75.    EDITOR_WINDOW_LEFT, EDITOR_WINDOW_TOP, EDITOR_WINDOW_WIDTH,
  76.    EDITOR_WINDOW_HEIGHT, 0, 1, EDITOR_WINDOW_IDCMP, EDITOR_WINDOW_FLAGS,
  77.    NULL, NULL, EDITOR_WINDOW_TITLE, NULL, NULL, 0, 0, 0, 0, WBENCHSCREEN
  78. };
  79.     /* Main routine */
  80.  
  81.    LONG
  82. main(VOID)
  83. {
  84.    LONG return_code = RETURN_ERROR;
  85.  
  86.    MWInit((BPTR)NULL, (LONG)MWF_NOATRASH);
  87.    if (IntuitionBase = OpenLibrary("intuition.library", 0L)) {
  88.       if (GfxBase = OpenLibrary("graphics.library", 0L)) {
  89.      if (!(ArpBase = OpenLibrary(ArpName, ArpVersion))) {
  90.         show_error(EDITOR_ERROR_NO_ARP);
  91.      } else {
  92.         if (!(IntuiSupBase = OpenLibrary(IntuiSupName,
  93.                             IntuiSupVersion))) {
  94.            show_error(EDITOR_ERROR_NO_INTUISUP);
  95.         } else {
  96.            if (!(DiskfontBase = OpenLibrary("diskfont.library", 0L))) {
  97.           show_error(EDITOR_ERROR_NO_DISKFONT);
  98.            } else {
  99.           return_code = init_resources();
  100.           CloseLibrary(DiskfontBase);
  101.            }
  102.            CloseLibrary(IntuiSupBase);
  103.         }
  104.         CloseLibrary(ArpBase);
  105.      }
  106.      CloseLibrary(GfxBase);
  107.       }
  108.       CloseLibrary(IntuitionBase);
  109.    }
  110.    MWTerm();
  111.    return(return_code);
  112. }
  113.     /* Init resources */
  114.  
  115.    LONG
  116. init_resources(VOID)
  117. {
  118.    SHORT status;
  119.    LONG  return_code = RETURN_OK;
  120.  
  121.    GetScreenData((BYTE *)&wb_screen, (LONG)sizeof(struct Screen), (LONG)
  122.                        WBENCHSCREEN, (struct Screen *)NULL);
  123.    /* Init and open editor window */
  124.    if (!(eri = IGetRenderInfo((struct Screen *)NULL,
  125.                          EDIT_RENDER_INFO_FLAGS))) {
  126.       status = EDITOR_ERROR_OUT_OF_MEM;
  127.    } else {
  128.       editor_new_window.LeftEdge = (wb_screen.Width -
  129.                            editor_new_window.Width) / 2;
  130.       if (!(ewin = IOpenWindow(eri, &editor_new_window,
  131.                          EDIT_OPEN_WINDOW_FLAGS))) {
  132.      status = EDITOR_ERROR_NO_WINDOW;
  133.       } else {
  134.  
  135.      /* Init and open project window */
  136.      pri  = NULL;
  137.      pwin = NULL;
  138.      if ((status = new_project_window(TEMPLATE_LIST_FLAG_DEFAULT_WINDOW))
  139.                           == EDITOR_STATUS_NORMAL) {
  140.         /* Init ARP file requester structs */
  141.         if (!(project_file_requester = ArpAllocFreq())) {
  142.            status = EDITOR_ERROR_OUT_OF_MEM;
  143.         } else {
  144.            if (!(csource_file_requester = ArpAllocFreq())) {
  145.           status = EDITOR_ERROR_OUT_OF_MEM;
  146.            } else {
  147.           status = editor_action_loop();
  148.            }
  149.         }
  150.      }
  151.  
  152.      /* Free resources */
  153.      if (pwin) {
  154.         CloseWindow(pwin);
  155.      }
  156.      if (pri) {
  157.         IFreeRenderInfo(pri);
  158.      }
  159.      CloseWindow(ewin);
  160.       }
  161.       IFreeRenderInfo(eri);
  162.    }
  163.    if (status < EDITOR_STATUS_NORMAL) {
  164.       show_error(status);
  165.       return_code = RETURN_ERROR;
  166.    }
  167.    return(return_code);
  168. }
  169.